package com.runvp.common.util.enc.aes128gcm;

import java.nio.charset.StandardCharsets;

public class HexStringToASCII {
    public static String convert(String hexString) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < hexString.length() - 1; i += 2) {
            String hex = hexString.substring(i, i + 2);
            int decimal = Integer.parseInt(hex, 16);
            sb.append((char) decimal);
        }
        return sb.toString();
    }


    public static String hexToAscii(String hexString) {
        byte[] bytes = new byte[hexString.length() / 2];
        for (int i = 0, j = 0; i < hexString.length(); i += 2, j++) {
            String hex = hexString.substring(i, i + 2);
            bytes[j] = (byte) Integer.parseInt(hex, 16);
        }
        return new String(bytes, StandardCharsets.UTF_8);
    }
    public static  byte[] hexToAsciiByte(String hexString) {
        byte[] bytes = new byte[hexString.length() / 2];
        for (int i = 0, j = 0; i < hexString.length(); i += 2, j++) {
            String hex = hexString.substring(i, i + 2);
            bytes[j] = (byte) Integer.parseInt(hex, 16);
        }
        return bytes;
    }

    public static void main(String[] args) {
        System.out.println(hexToAscii("7b22736e223a22383632333533303639393833393232222c227479223a317d"));
    }
}